<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 7.3.0">

  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.ico">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.ico">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha256-wiz7ZSCn/btzhjKDQBms9Hx4sSeUYsDrTLg7roPstac=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.css" integrity="sha256-6cQIC71/iBIYXFK+0RHAvwmjwWzkWd+r7v/BX3/vZDc=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/themes/green/pace-theme-minimal.css">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/pace.min.js" integrity="sha256-gqd7YTjg/BtfqWSwsJOvndl0Bxc8gFImLEkXQT8+qj0=" crossorigin="anonymous"></script>

<script class="next-config" data-name="main" type="application/json">{"hostname":"sumumm.github.io","root":"/","images":"/images","scheme":"Gemini","darkmode":false,"version":"8.19.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":{"enable":true,"style":"mac"},"fold":{"enable":true,"height":300},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":true,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":true,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}}</script><script src="/js/config.js"></script>

    <meta name="description" content="本文主要是串口通信——UART基础知识的相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:type" content="article">
<meta property="og:title" content="LV04-04-串口通信-01-UART基础">
<meta property="og:url" content="https://sumumm.github.io/post/5091c1fe.html">
<meta property="og:site_name" content="苏木">
<meta property="og:description" content="本文主要是串口通信——UART基础知识的相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-04-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1-01-UART%E5%9F%BA%E7%A1%80/img/image-20230729103935953.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-04-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1-01-UART%E5%9F%BA%E7%A1%80/img/image-20230729104827593.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-04-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1-01-UART%E5%9F%BA%E7%A1%80/img/image-20230729104903289.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-04-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1-01-UART%E5%9F%BA%E7%A1%80/img/image-20230729105134577.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-04-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1-01-UART%E5%9F%BA%E7%A1%80/img/image-20230729104956715.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-04-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1-01-UART%E5%9F%BA%E7%A1%80/img/image-20230729105052898.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-04-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1-01-UART%E5%9F%BA%E7%A1%80/img/image-20230729105432453.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-04-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1-01-UART%E5%9F%BA%E7%A1%80/img/image-20230729124950110.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-04-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1-01-UART%E5%9F%BA%E7%A1%80/img/image-20230729125123876.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-04-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1-01-UART%E5%9F%BA%E7%A1%80/img/image-20230729125301922.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-04-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1-01-UART%E5%9F%BA%E7%A1%80/img/image-20230729125444918.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-04-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1-01-UART%E5%9F%BA%E7%A1%80/img/image-20230729130059327.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-04-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1-01-UART%E5%9F%BA%E7%A1%80/img/image-20230729131032334.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-04-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1-01-UART%E5%9F%BA%E7%A1%80/img/image-20230729131444598.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-04-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1-01-UART%E5%9F%BA%E7%A1%80/img/image-20230729131538537.png">
<meta property="article:published_time" content="2023-09-08T11:24:09.000Z">
<meta property="article:modified_time" content="2025-06-13T16:25:57.039Z">
<meta property="article:author" content="苏木">
<meta property="article:tag" content="(ALPHA)LV04-裸机开发">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-04-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1-01-UART%E5%9F%BA%E7%A1%80/img/image-20230729103935953.png">


<link rel="canonical" href="https://sumumm.github.io/post/5091c1fe.html">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"https://sumumm.github.io/post/5091c1fe.html","path":"post/5091c1fe.html","title":"LV04-04-串口通信-01-UART基础"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>LV04-04-串口通信-01-UART基础 | 苏木</title>
  








    <script src="/js/browser_tools_disable.js"></script>

  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
<!-- hexo injector head_end start --><link rel="stylesheet" href="https://unpkg.com/hexo-next-tags-plus@latest/lib/tag_plus.css" media="defer" onload="this.media='all'"><!-- hexo injector head_end end --></head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">苏木</p>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">我的学习之路</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>苏木的家</a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类页<span class="badge">42</span></a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档页<span class="badge">673</span></a></li><li class="menu-item menu-item-flink"><a href="/flink/" rel="section"><i class="fa fa-link fa-fw"></i>友人帐</a></li><li class="menu-item menu-item-about"><a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于我</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%80%E3%80%81UART%E7%AE%80%E4%BB%8B"><span class="nav-text">一、UART简介</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-UART-%E9%80%9A%E4%BF%A1%E6%A0%BC%E5%BC%8F"><span class="nav-text">1. UART 通信格式  </span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-UART-%E7%A1%AC%E4%BB%B6%E8%BF%9E%E6%8E%A5"><span class="nav-text">2. UART 硬件连接  </span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#2-1-TTL-%E7%94%B5%E5%B9%B3%E4%B8%89%E7%BA%BF%E8%BF%9E%E6%8E%A5"><span class="nav-text">2.1 TTL 电平三线连接  </span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-2-TTL-%E7%94%B5%E5%B9%B3%E8%BD%AC-USB-%E7%94%B5%E5%B9%B3"><span class="nav-text">2.2 TTL 电平转 USB 电平  </span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%BA%8C%E3%80%81I-MX6ULL-UART"><span class="nav-text">二、I.MX6ULL UART</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-UART%E6%A8%A1%E5%9D%97%E7%AE%80%E4%BB%8B"><span class="nav-text">1. UART模块简介</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E9%83%BD%E6%9C%89%E5%93%AA%E4%BA%9B%E5%AF%84%E5%AD%98%E5%99%A8%EF%BC%9F"><span class="nav-text">2. 都有哪些寄存器？</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E5%AF%84%E5%AD%98%E5%99%A8%E7%AE%80%E4%BB%8B"><span class="nav-text">3. 寄存器简介</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#3-1-UARTx-URXD"><span class="nav-text">3.1 UARTx_URXD  </span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-2-UARTx-UTXD"><span class="nav-text">3.2 UARTx_UTXD  </span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-3-UARTx-UCR1"><span class="nav-text">3.3 UARTx_UCR1  </span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-4-UARTx-UCR2"><span class="nav-text">3.4 UARTx_UCR2  </span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-5-UARTx-UCR3"><span class="nav-text">3.5 UARTx_UCR3  </span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-6-UARTx-USR2"><span class="nav-text">3.6 UARTx_USR2  </span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-7-UARTx-UFCR"><span class="nav-text">3.7 UARTx_UFCR  </span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-8-UARTx-UBIR-%E4%B8%8E-UARTx-UBMR"><span class="nav-text">3.8 UARTx_UBIR 与 UARTx_UBMR  </span></a></li></ol></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="苏木"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">苏木</p>
  <div class="site-description" itemprop="description">莫道桑榆晚，为霞尚满天</div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">673</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">42</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
        <span class="site-state-item-count">43</span>
        <span class="site-state-item-name">标签</span>
      </div>
  </nav>
</div>
  <div class="links-of-author animated">
      <span class="links-of-author-item">
        <a href="https://github.com/sumumm" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;sumumm" rel="noopener me" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
  </div>

        </div>
      </div>
    </div>

    
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://sumumm.github.io/post/5091c1fe.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="苏木">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏木">
      <meta itemprop="description" content="莫道桑榆晚，为霞尚满天">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="LV04-04-串口通信-01-UART基础 | 苏木">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          LV04-04-串口通信-01-UART基础
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2023-09-08 19:24:09" itemprop="dateCreated datePublished" datetime="2023-09-08T19:24:09+08:00">2023-09-08</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/" itemprop="url" rel="index"><span itemprop="name">嵌入式开发</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/" itemprop="url" rel="index"><span itemprop="name">02IMX6ULL平台</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/" itemprop="url" rel="index"><span itemprop="name">LV04-裸机开发</span></a>
        </span>
    </span>

  
    <span class="post-meta-break"></span>
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>4.7k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>17 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody"><p>本文主要是串口通信——UART基础知识的相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。</p>
<span id="more"></span>

<!-- Photo: https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-04-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1-01-UART%E5%9F%BA%E7%A1%80/img/ -->

<details class="folding-tag" blue><summary> 点击查看使用工具及版本 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center" width=150px>Windows版本</td>        <td align="left">windows11</td>    </tr>    <tr>        <td align="center">Ubuntu版本</td>        <td align="left">Ubuntu16.04的64位版本</td>      </tr>    <tr>        <td align="center">VMware® Workstation 16 Pro</td>        <td align="left">16.2.3 build-19376536</td>      </tr>    <tr>        <td align="center">终端软件</td>        <td align="left">MobaXterm(Professional Edition v23.0 Build 5042 (license))</td>      </tr>    <tr>        <td align="center">Linux开发板</td>        <td align="left">正点原子 i.MX6ULL Linux 阿尔法开发板</td>      </tr>    <tr>        <td align="center">uboot</td>        <td align="left">NXP官方提供的uboot，NXP提供的版本为uboot-imx-rel_imx_4.1.15_2.1.0_ga(使用的uboot版本为U-Boot 2016.03)</td>      </tr>    <tr>        <td align="center">linux内核</td>        <td align="left">linux-4.15(NXP官方提供)</td>      </tr>    <tr>        <td align="center">Win32DiskImager</td>        <td align="left">Win32DiskImager v1.0</td>      </tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看本文参考资料 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center">分类</td>        <td align="center">网址</td>        <td align="center">说明</td>    </tr>    <tr>        <td align="center" rowspan="5">官方网站</td>        <td align="left"><a href="https://www.arm.com/" target="_blank">https://www.arm.com/</a></td>        <td align="left">ARM官方网站，在这里我们可以找到Cotex-Mx以及ARMVx的一些文档</td>    </tr>    <tr>        <td align="left"><a href="https://www.nxp.com.cn/" target="_blank">https://www.nxp.com.cn/ </a></td>        <td align="left">NXP官方网站</td>    </tr>    <tr>        <td align="left"><a href="https://www.nxpic.org.cn/" target="_blank">https://www.nxpic.org.cn/</a></td><td align="left">NXP 官方社区</td>    </tr>    <tr>        <td align="left"><a href="https://u-boot.readthedocs.io/en/latest/" target="_blank">https://u-boot.readthedocs.io/en/latest/</a></td><td align="left">u-boot官网</td>    </tr>    <tr>        <td align="left"><a href="https://www.kernel.org/" target="_blank">https://www.kernel.org/</a></td><td align="left">linux内核官网</td>    </tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看相关文件下载 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center">分类</td>        <td align="center">网址</td>        <td align="center">说明</td>    </tr>    <tr>        <td align="center" rowspan="4">NXP</td>        <td align="left"><a href="https://github.com/nxp-imx" target="_blank">https://github.com/nxp-imx</a></td>        <td align="left">NXP imx开发资源GitHub组织，里边会有u-boot和linux内核的仓库</td>    </tr>    <tr>        <td align="left"><a href="https://elixir.bootlin.com/linux/latest/source" target="_blank">https://elixir.bootlin.com/linux/latest/source</a></td>        <td align="left">在线阅读linux kernel源码</td>    </tr>    <tr>        <td align="left"><a href="https://github.com/nxp-imx/linux-imx/releases/tag/rel_imx_4.1.15_2.1.0_ga" target="_blank">nxp-imx/linux-imx/releases/tag/rel_imx_4.1.15_2.1.0_ga</a></td>        <td align="left">NXP linux内核仓库tags中的rel_imx_4.1.15_2.1.0_ga</td>    </tr>    <tr>        <td align="left"><a href="https://github.com/nxp-imx/uboot-imx/releases/tag/rel_imx_4.1.15_2.1.0_ga" target="_blank">nxp-imx/uboot-imx/releases/tag/rel_imx_4.1.15_2.1.0_ga</a></td>        <td align="left">NXP u-boot仓库tags中的rel_imx_4.1.15_2.1.0_ga</td>    </tr>    <tr>        <td align="center" rowspan="2">I.MX6ULL</td>        <td align="left"><a href="https://www.nxp.com.cn/docs/en/data-sheet/IMX6ULLIEC.pdf" target="_blank">i.MX 6ULL Applications Processors for Industrial Products</a></td>        <td align="left">I.MX6ULL 芯片手册（datasheet，可以在线查看）</td>    </tr>    <tr>        <td align="left"><a href="https://www.nxp.com.cn/webapp/Download?colCode=IMX6ULLRM&lang_cd=zh" target="_blank">i.MX 6ULL Applications ProcessorReference Manual</a></td>        <td align="left">I.MX6ULL 参考手册（下载后才能查看，需要登录NXP官网）</td>    </tr></table>
              </div>
            </details>

<h1 id="一、UART简介"><a href="#一、UART简介" class="headerlink" title="一、UART简介"></a><font size=3>一、UART简介</font></h1><h2 id="1-UART-通信格式"><a href="#1-UART-通信格式" class="headerlink" title="1. UART 通信格式  "></a><font size=3>1. UART 通信格式  </font></h2><p>串口全称叫做串行接口，通常也叫做 COM 接口，串行接口指的是数据一个一个的顺序传输，通信线路简单。使用两条线即可实现双向通信，一条用于发送，一条用于接收。串口通信距离远，但是速度相对会低，串口是一种很常用的工业接口。 I.MX6U 自带的 UART 外设就是串口的一种， UART 全称是 Universal Asynchronous Receiver&#x2F;Trasmitter，也就是异步串行收发器。</p>
<p>既然有异步串行收发器，那肯定也有同步串行收发器，叫USART。USART 的全 称 是 Universal Synchronous&#x2F;Asynchronous Receiver&#x2F;Transmitter，也就是同步&#x2F;异步串行收发器。 相比 UART 多了一个同步的功能，在硬件上体现出来的就是多了一条时钟线。 一般 USART 是可以作为 UART使用的，也就是不使用其同步的功能。</p>
<p>UART 作为串口的一种，其工作原理也是将数据一位一位的进行传输，发送和接收各用一条线，因此通过 UART 接口与外界相连最少只需要三条线：TXD(发送)、 RXD(接收)和 GND(地线)。  UART 之间为何能够准确可靠的的发送和接收数据？首先我们需要约定好传输速率（每一秒传输的数据位数，即波特率），一般选择 9600,19200,115200 等。确定好传输速率后，我们还需要确定传输数据的格式， UART 串口通信的数据包以帧为单位，常用的帧结构为： 1 位起始位+8 位数据位+1 位奇偶校验位（可选） +1 位停止位。举例说明，如下图：  </p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-04-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1-01-UART%E5%9F%BA%E7%A1%80/img/image-20230729103935953.png" alt="image-20230729103935953" style="zoom:50%;" />

<p>该图就是 UART通信中 <code>1位起始位+8位数据位+1位偶校验位+1位停止位</code> 的波形。  根据查找 ASCII 码表得知’ A ’字符的 ASCII 值为 41（十进制），将其转换成<br>二进制应该为 0100 0001，小端传输，即低位（ LSB）在前，高位（ MSB）在后，和上图所示一致。  </p>
<p>（1）<strong>空闲位</strong>：平时没有数据时，数据线为高电平（逻辑 1）；</p>
<p>（2）<strong>起始位</strong>：当需要发送数据时， UART 将改变 UARTx_TXD 的状态，变为低电平，即为上图中的起始位（逻辑 0）；</p>
<p>（3）<strong>数据位</strong>：可以有 5、 6、 7 或 8 位的数据，一般我们是按字节（8 位）传输数据，发送方一位一位的改变数据线上的状态（高电平或低电平）将它们发送出去，传输数据时先传最低位，最后传送最高位。字符’ A ’的 8 位二进制字符是 0100 0001，先发送最低位 bit 0，其值为1；再发送 bit 1，其值为 0，如此继续；最后发送最高位 bit 7，其值为 0。</p>
<p>（4）<strong>奇偶校验位</strong>：如果使用了奇偶校验功能，有效数据位发送完毕后，还要发送1 个校验位（奇偶校验位）。有两种校验方法：奇校验，偶校验——数据位连同校验位中，“1”的数目等于奇数或偶数。奇偶校验只能检错，不能纠错的。而且只能检测 1 位误码，检测出有错后只能要求重发，没法纠正的。上图中使用的是偶较验，即 8 个数据位和 1 个校验位中，一共有偶数个“1”： 2 个。</p>
<p>（5）<strong>停止位</strong>：停止位（逻辑 1）用来表示当前数据传输完毕。停止位的长度有三种： 1 位， 1.5 位， 2 位，通常我们选择 1 位即可。</p>
<h2 id="2-UART-硬件连接"><a href="#2-UART-硬件连接" class="headerlink" title="2. UART 硬件连接  "></a><font size=3>2. UART 硬件连接  </font></h2><h3 id="2-1-TTL-电平三线连接"><a href="#2-1-TTL-电平三线连接" class="headerlink" title="2.1 TTL 电平三线连接  "></a><font size=3>2.1 TTL 电平三线连接  </font></h3><p>UART 串口最精简的连接是 TTL 电平三线连接  </p>
<p>（1）UARTx_TXD：用于发送数据，应连接到接收设备的 UARTx_RXD 引脚上；</p>
<p>（2）UARTx_RXD：用于接收数据，应连接到发送设备的 UARTx_TXD 引脚上；</p>
<p>（3）GND：为双方提供一个相同的参考电平。  </p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-04-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1-01-UART%E5%9F%BA%E7%A1%80/img/image-20230729104827593.png" alt="image-20230729104827593" style="zoom:50%;" />

<p>上图为 UART 串口 TTL 电平硬件连接，此时使用标准的 TTL 电平来表示数据，高电平表示 1，低电平表示 0，标准 TTL 输入高电平最小 2V，输出高电平最小 2.4V，典型值为 3.4V，输入低电平最大 0.8V，输出低电平最大 0.4V，典型值为 0.2V。直接采用 TTL 电平进行串行通讯，由于其抗干扰能力差，导致传输距离短，且容易出现数据不可靠的情况。  为提高抗干扰能力和传输距离，一般采用下面的硬件连接方式：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-04-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1-01-UART%E5%9F%BA%E7%A1%80/img/image-20230729104903289.png" alt="image-20230729104903289" style="zoom:50%;" />

<p>RS232 电平规定逻辑“ 1”的电平为-5V~-15 V，逻辑“0”的电平为+5 V～+15 V，选用该电气标准以提高抗干扰能力。常用的 TTL 转 RS232 芯片有：MAX232， SP3232 等。  </p>
<p>RS-232 电平需要 DB9 接口， I.MX6U-ALPHA 开发板上的 COM3(UART3)口就是 RS-232 接口的，如图所示：  </p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-04-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1-01-UART%E5%9F%BA%E7%A1%80/img/image-20230729105134577.png" alt="image-20230729105134577" style="zoom: 50%;" />



<h3 id="2-2-TTL-电平转-USB-电平"><a href="#2-2-TTL-电平转-USB-电平" class="headerlink" title="2.2 TTL 电平转 USB 电平  "></a><font size=3>2.2 TTL 电平转 USB 电平  </font></h3><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-04-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1-01-UART%E5%9F%BA%E7%A1%80/img/image-20230729104956715.png" alt="image-20230729104956715" style="zoom:50%;" />

<p>将 TTL 电平转换为 USB 电平（ D+与 D-一对差分信号采用 NRZI 编码实现通讯），提高抗干扰能力，常用的 TTL 转 USB 芯片有： PL2303， CH340, CP2102等 ，常见的转换模块就是CH340啦，如下图所示：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-04-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1-01-UART%E5%9F%BA%E7%A1%80/img/image-20230729105052898.png" alt="image-20230729105052898" style="zoom:50%;" />

<p>改模块就是 USB 转 TTL 模块， TTL 接口部分有 VCC、 GND、 RXD、 TXD、RTS 和 CTS。 RTS 和 CTS 基本用不到，使用的时候通过杜邦线和其他模块的 TTL 接口相连即可。  </p>
<p>由于现在的电脑都没有 DB9 接口了，取而代之的是 USB 接口，所以就催生出了很多 USB转串口 TTL 芯片，就比如上边说的。通过这些芯片就可以实现串口 TTL 转 USB。I.MX6UALPHA开发板就使用CH340 芯片来完成UART1 和电脑之间的连接，只需要一条USB 线即可，如图所示。  </p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-04-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1-01-UART%E5%9F%BA%E7%A1%80/img/image-20230729105432453.png" alt="image-20230729105432453" style="zoom:50%;" />

<h1 id="二、I-MX6ULL-UART"><a href="#二、I-MX6ULL-UART" class="headerlink" title="二、I.MX6ULL UART"></a><font size=3>二、I.MX6ULL UART</font></h1><p>接下来就来了解一下I.MX6ULL的UART吧。主要参考《i.MX 6ULL Applications ProcessorReference Manual》参考手册的Chapter 55 Universal Asynchronous Receiver&#x2F;Transmitter (UART)  一节。</p>
<h2 id="1-UART模块简介"><a href="#1-UART模块简介" class="headerlink" title="1. UART模块简介"></a><font size=3>1. UART模块简介</font></h2><p>IMX6ULL 共 8 个独立的 UART 通道，即 8 个 UART，主要特性如下：</p>
<p>①、兼容 TIA&#x2F;EIA-232F 标准，速度最高可到 5Mbit&#x2F;S。</p>
<p>②、支持串行 IR 接口，兼容 IrDA，最高可到 115.2Kbit&#x2F;s。</p>
<p>③、支持 9 位或者多节点模式(RS-485)。</p>
<p>④、 1 或 2 位停止位。</p>
<p>⑤、可编程的奇偶校验(奇校验和偶校验)。</p>
<p>⑥、自动波特率检测(最高支持 115.2Kbit&#x2F;S)。  </p>
<h2 id="2-都有哪些寄存器？"><a href="#2-都有哪些寄存器？" class="headerlink" title="2. 都有哪些寄存器？"></a><font size=3>2. 都有哪些寄存器？</font></h2><p>我们可以看一下《i.MX 6ULL Applications ProcessorReference Manual》参考手册的Chapter 55 Universal Asynchronous Receiver&#x2F;Transmitter (UART)</p>
<p>下的55.15 UART Memory Map&#x2F;Register Definition  ，这一节有一个表格汇总了UART的所有寄存器。</p>
<h2 id="3-寄存器简介"><a href="#3-寄存器简介" class="headerlink" title="3. 寄存器简介"></a><font size=3>3. 寄存器简介</font></h2><h3 id="3-1-UARTx-URXD"><a href="#3-1-UARTx-URXD" class="headerlink" title="3.1 UARTx_URXD  "></a><font size=3>3.1 UARTx_URXD  </font></h3><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-04-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1-01-UART%E5%9F%BA%E7%A1%80/img/image-20230729124950110.png" alt="image-20230729124950110" style="zoom:50%;" />

<p>主要用于接收串口数据的寄存器，只有低八位的空间是存储接收数据的，其他是一些判断位，基本用不上；有数据时，读取这个寄存器就可以得到数据。  </p>
<h3 id="3-2-UARTx-UTXD"><a href="#3-2-UARTx-UTXD" class="headerlink" title="3.2 UARTx_UTXD  "></a><font size=3>3.2 UARTx_UTXD  </font></h3><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-04-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1-01-UART%E5%9F%BA%E7%A1%80/img/image-20230729125123876.png" alt="image-20230729125123876" style="zoom:50%;" />

<p>用于发送串口数据的寄存器，只有低八位的空间用于发送数据，其他位保留不使用；要发送数据时，写入这个寄存器就可以了。  </p>
<h3 id="3-3-UARTx-UCR1"><a href="#3-3-UARTx-UCR1" class="headerlink" title="3.3 UARTx_UCR1  "></a><font size=3>3.3 UARTx_UCR1  </font></h3><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-04-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1-01-UART%E5%9F%BA%E7%A1%80/img/image-20230729125301922.png" alt="image-20230729125301922" style="zoom: 50%;" />

<p>控制寄存器 1，用于设置串口各类功能的使能，例如自动波特率检测的使能，发送中断，串口 DMA 使能，串口使能等。寄存器 UARTx_UCR1 我们用到的重要位如下：</p>
<p>**ADBR(bit14)**：自动波特率检测使能位，为 0 的时候关闭自动波特率检测，为 1 的时候使能自动波特率检测。</p>
<p>**UARTEN(bit0)**： UART 使能位，为 0 的时候关闭 UART，为 1 的时候使能 UART。  </p>
<h3 id="3-4-UARTx-UCR2"><a href="#3-4-UARTx-UCR2" class="headerlink" title="3.4 UARTx_UCR2  "></a><font size=3>3.4 UARTx_UCR2  </font></h3><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-04-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1-01-UART%E5%9F%BA%E7%A1%80/img/image-20230729125444918.png" alt="image-20230729125444918" style="zoom:50%;" />

<p>控制寄存器 2：主要用于设置串口的发送帧格式，帧长，是否奇偶校验，是否忽略有 RTS，软复位等 。寄存器 UARTx_UCR2 用到的重要位如下：</p>
<p>**IRTS(bit14)**：为 0 的时候使用 RTS 引脚功能，为 1 的时候忽略 RTS 引脚。</p>
<p>**PREN(bit8)**：奇偶校验使能位，为 0 的时候关闭奇偶校验，为 1 的时候使能奇偶校验。</p>
<p>**PROE(bit7)**：奇偶校验模式选择位，开启奇偶校验以后此位如果为 0 的话就使用偶校验，此位为 1 的话就使能奇校验。</p>
<p>**STOP(bit6)**：停止位数量，为 0 的话 1 位停止位，为 1 的话 2 位停止位。</p>
<p>**WS(bit5)**：数据位长度，为 0 的时候选择 7 位数据位，为 1 的时候选择 8 位数据位。</p>
<p>**TXEN(bit2)**：发送使能位，为 0 的时候关闭 UART 的发送功能，为 1 的时候打开 UART的发送功能。</p>
<p>**RXEN(bit1)**：接收使能位，为 0 的时候关闭 UART 的接收功能，为 1 的时候打开 UART的接收功能。</p>
<p>**SRST(bit0)**：软件复位，为 0 的是时候软件复位 UART，为 1 的时候表示复位完成。复位完成以后此位会自动置 1，表示复位完成。此位只能写 0，写 1 会被忽略掉。  </p>
<h3 id="3-5-UARTx-UCR3"><a href="#3-5-UARTx-UCR3" class="headerlink" title="3.5 UARTx_UCR3  "></a><font size=3>3.5 UARTx_UCR3  </font></h3><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-04-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1-01-UART%E5%9F%BA%E7%A1%80/img/image-20230729130059327.png" alt="image-20230729130059327" style="zoom:50%;" />

<p>控制寄存器 3：一般只设置 bit2，官方要求设置，属于芯片特点。也就是RXDMUXSEL(bit2)，这个位应该始终为 1，这个在《i.MX 6ULL Applications ProcessorReference Manual》第 3624 页有说明。    </p>
<h3 id="3-6-UARTx-USR2"><a href="#3-6-UARTx-USR2" class="headerlink" title="3.6 UARTx_USR2  "></a><font size=3>3.6 UARTx_USR2  </font></h3><p>串口状态寄存器，该寄存器里面主要是一些串口的状态位。寄存器 UARTx_USR2 用到的重要位如下：</p>
<p>**TXDC(bit3)**：发送完成标志位，为 1 的时候表明发送缓冲(TxFIFO)和移位寄存器为空，也就是发送完成，向 TxFIFO 写入数据此位就会自动清零。</p>
<p>**RDR(bit0)**：数据接收标志位，为 1 的时候表明至少接收到一个数据，从寄存器UARTx_URXD 读取数据接收到的数据以后此位会自动清零。    </p>
<h3 id="3-7-UARTx-UFCR"><a href="#3-7-UARTx-UFCR" class="headerlink" title="3.7 UARTx_UFCR  "></a><font size=3>3.7 UARTx_UFCR  </font></h3><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-04-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1-01-UART%E5%9F%BA%E7%A1%80/img/image-20230729131032334.png" alt="image-20230729131032334" style="zoom:50%;" />

<p>串口 FIFO 控制寄存器，设置发送与接收的 fifo 的大小，最大 32 字节，串口时钟分频系数等。寄存器UARTx_UFCR 中我们要用到的是位 RFDIV(bit9:7)，用来设置参考时钟分频：</p>
<table>
<thead>
<tr>
<th align="center">RFDIV(bit9:7)</th>
<th align="center">分频值</th>
</tr>
</thead>
<tbody><tr>
<td align="center">000</td>
<td align="center">6 分频</td>
</tr>
<tr>
<td align="center">001</td>
<td align="center">5 分频</td>
</tr>
<tr>
<td align="center">010</td>
<td align="center">4 分频</td>
</tr>
<tr>
<td align="center">011</td>
<td align="center">3 分频</td>
</tr>
<tr>
<td align="center">100</td>
<td align="center">2 分频</td>
</tr>
<tr>
<td align="center">101</td>
<td align="center">1 分频</td>
</tr>
<tr>
<td align="center">110</td>
<td align="center">7 分频</td>
</tr>
<tr>
<td align="center">111</td>
<td align="center">保留</td>
</tr>
</tbody></table>
<h3 id="3-8-UARTx-UBIR-与-UARTx-UBMR"><a href="#3-8-UARTx-UBIR-与-UARTx-UBMR" class="headerlink" title="3.8 UARTx_UBIR 与 UARTx_UBMR  "></a><font size=3>3.8 UARTx_UBIR 与 UARTx_UBMR  </font></h3><p>用于设置波特率，即每秒可传输的位数 ，通过UARTx_UFCR 、 UARTx_UBIR 和 UARTx_UBMR  这三个寄存器，可以设置 UART 的波特率，波特率的计算公式如下 ：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-04-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1-01-UART%E5%9F%BA%E7%A1%80/img/image-20230729131444598.png" alt="image-20230729131444598" style="zoom:50%;" />

<p>Ref Freq：经过分频以后进入 UART 的最终时钟频率。</p>
<p>UBMR：寄存器 UARTx_UBMR 中的值。</p>
<p>UBIR：寄存器 UARTx_UBIR 中的值。  </p>
<p>通过 UARTx_UFCR 的 RFDIV 位、 UARTx_UBMR 和 UARTx_UBIR 这三者的配合即可得到我们想要的波特率。比如现在要设置 UART 波特率为 115200，那么可以设置 RFDIV 为5(0b101)，也就是 1 分频，因此 Ref Freq&#x3D;80MHz。设置 UBIR&#x3D;71， UBMR&#x3D;3124，根据上面的公式可以得到：  </p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-04-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1-01-UART%E5%9F%BA%E7%A1%80/img/image-20230729131538537.png" alt="image-20230729131538537" style="zoom:50%;" />

    </div>

    
    
    

    <footer class="post-footer">




    <div>
        
            <div style="text-align:center;color: #ccc;font-size:14px;">
            ----------本文结束
            <i class="fas fa-fan fa-spin" style="color: #FF1493; font-size: 1rem"></i>
            感谢您的阅读----------
            </div>
        
    </div>





  
  <div class="my_post_copyright"> 
    <p><span>文章标题:</span><a href="/post/5091c1fe.html">LV04-04-串口通信-01-UART基础</a></p>
    <p><span>文章作者:</span><a href="/" title="欢迎访问 《苏木》 的学习笔记">苏木</a></p>
    <p><span>发布时间:</span>2023年09月08日 - 19:24</p>
    <p><span>最后更新:</span>2025年06月14日 - 00:25</p>
    <p><span>原始链接:</span><a href="/post/5091c1fe.html" title="LV04-04-串口通信-01-UART基础">https://sumumm.github.io/post/5091c1fe.html</a></p>
    <p><span>许可协议:</span><i class="fab fa-creative-commons"></i> <a rel="license" href= "https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank" title="Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)">署名-非商业性使用-禁止演绎 4.0 国际</a> 转载请保留原文链接及作者。</p>  
  </div>
  


          <div class="post-tags">
              <a href="/tags/ALPHA-LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/" rel="tag"><i class="fa fa-tag"></i> (ALPHA)LV04-裸机开发</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/post/28f07778.html" rel="prev" title="LV04-04-串口通信-02-IMX6ULL的UART配置">
                  <i class="fa fa-angle-left"></i> LV04-04-串口通信-02-IMX6ULL的UART配置
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/post/254de3ea.html" rel="next" title="LV04-03-BSP工程管理-02-管理工程">
                  LV04-03-BSP工程管理-02-管理工程 <i class="fa fa-angle-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">

  <div class="copyright">
    &copy; 2017 – 
    <span itemprop="copyrightYear">2025</span>
    <span class="with-love">
      <i class="fa fa-heart"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">苏木</span>
  </div>
<div class="wordcount">
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-line"></i>
    </span>
      <span>站点总字数：</span>
    <span title="站点总字数">3.7m</span>
  </span>
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span>站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">225:26</span>
  </span>
</div>




    <span id="sitetime"></span>
    <script defer language=javascript>
        function siteTime()
        {
            window.setTimeout("siteTime()", 1000);
            var seconds = 1000;
            var minutes = seconds * 60;
            var hours = minutes * 60;
            var days = hours * 24;
            var years = days * 365;
            var today = new Date();
            var todayYear = today.getFullYear();
            var todayMonth = today.getMonth()+1;
            var todayDate = today.getDate();
            var todayHour = today.getHours();
            var todayMinute = today.getMinutes();
            var todaySecond = today.getSeconds();
            /*==================================================
            Date.UTC() -- 返回date对象距世界标准时间(UTC)1970年1月1日午夜之间的毫秒数(时间戳)
            year        - 作为date对象的年份，为4位年份值
            month       - 0-11之间的整数，做为date对象的月份
            day         - 1-31之间的整数，做为date对象的天数
            hours       - 0(午夜24点)-23之间的整数，做为date对象的小时数
            minutes     - 0-59之间的整数，做为date对象的分钟数
            seconds     - 0-59之间的整数，做为date对象的秒数
            microseconds - 0-999之间的整数，做为date对象的毫秒数
            ==================================================*/
            var t1 = Date.UTC(2017, 
                              5, 
                              19, 
                              0, 
                              0, 
                              0); //北京时间
            var t2 = Date.UTC(todayYear,todayMonth,todayDate,todayHour,todayMinute,todaySecond);
            var diff = t2-t1;
            var diffYears = Math.floor(diff/years);
            var diffDays = Math.floor((diff/days)-diffYears*365);
            var diffHours = Math.floor((diff-(diffYears*365+diffDays)*days)/hours);
            var diffMinutes = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours)/minutes);
            var diffSeconds = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours-diffMinutes*minutes)/seconds);
            document.getElementById("sitetime").innerHTML="已在这里 "+diffYears+" 年 "+diffDays+" 天 "+diffHours+" 小时 "+diffMinutes+" 分钟 "+diffSeconds+" 秒";
        }
        siteTime();
    </script>



    </div>
  </footer>

  
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up fa-lg"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/next-theme-pjax/0.6.0/pjax.min.js" integrity="sha256-vxLn1tSKWD4dqbMRyv940UYw4sXgMtYcK6reefzZrao=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.umd.js" integrity="sha256-ytMJGN3toR+a84u7g7NuHm91VIR06Q41kMWDr2pq7Zo=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/lozad.js/1.16.0/lozad.min.js" integrity="sha256-mOFREFhqmHeQbXpK2lp4nA3qooVgACfh88fpJftLBbc=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script><script src="/js/pjax.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/hexo-generator-searchdb/1.4.1/search.js" integrity="sha256-1kfA5uHPf65M5cphT2dvymhkuyHPQp5A53EGZOnOLmc=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>




  <script src="/js/third-party/fancybox.js"></script>

  <script src="/js/third-party/pace.js"></script>


  




  

  <script class="next-config" data-name="enableMath" type="application/json">true</script><script class="next-config" data-name="mathjax" type="application/json">{"enable":true,"tags":"none","js":{"url":"https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.js","integrity":"sha256-MASABpB4tYktI2Oitl4t+78w/lyA+D7b/s9GEP0JOGI="}}</script>
<script src="/js/third-party/math/mathjax.js"></script>


 
        <div id="click-show-text"
            data-mobile = false
            data-text = 富强,民主,文明,和谐,自由,平等,公正,法制,爱国,敬业,诚信,友善
            data-fontsize = 15px
            data-random= false>
        </div>
       

      
        <script async src=https://cdn.jsdelivr.net/npm/hexo-next-mouse-effect@latest/click/showText.js></script>
      

      
    




    <script async src="/js/fancybox_param.js"></script>





<!-- APlayer本体 -->



</body>
</html>
